//
//  UserAccountTool.swift
//  WB
//
//  Created by leador on 17/4/7.
//  Copyright © 2017年 袁满. All rights reserved.
//

import UIKit

class UserAccountViewModel {
    
    var account:UserAccount?
    
    //计算属性
    var accountPath:String {
        
        let accountPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        
        return accountPath.appending("/account.plist")
        
    }
    
    var isLogin:Bool {
        
        if account == nil {
            return false
        }
        
        guard let exprieseDate = account?.expires_date else {
            return false
        }
        
        return exprieseDate.compare(Date()) == .orderedDescending
        
    }
    
    static let shareInstance:UserAccountViewModel = UserAccountViewModel()
    
    init() {
        
        account = NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? UserAccount
        
        
    }
    
}
